package com.yu.hu

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.yu.hu.base.ui.theme.LiteAppScaffoldTheme
import com.yu.hu.feature.buildFeatureNavGraph
import com.yu.hu.navigation.AppNavHost
import com.yu.hu.feature.navigation.Main
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)
        //light主题下导航条会自动加白底遮罩，想要透明要么通过systemuicontroller
        //要么手动设置window?.isNavigationBarContrastEnforced = false
        //详见EdgeToEdgeApi29#setup实现
        enableEdgeToEdge()
        setContent {
            LiteAppScaffoldTheme {
                val darkTheme = isSystemInDarkTheme()
                val systemUiController = rememberSystemUiController()
                SideEffect {
                    systemUiController.setStatusBarColor(
                        color = Color.Transparent,
                        darkIcons = darkTheme
                    )
                    systemUiController.setNavigationBarColor(
                        color = Color.Transparent,
                        darkIcons = darkTheme,
                        navigationBarContrastEnforced = false // 防止厂商自动加亮蒙层
                    )
                }

                val navController = rememberNavController()
                AppNavHost(
                    navController = navController,
                    startDestination = Main
                ) {
                    buildFeatureNavGraph(navController)
                }
            }
        }

        // 不让启动界面一直显示
        splashScreen.setKeepOnScreenCondition { false }
    }
}